Load some packages that we’ll need to use to do these calculations:
library(tidyverse)
library(gifski)
library(ggraph)
library(here)
library(igraph)
source(here("modelFunction_rewiring.R"))
# Define parameters
N = 50
edge.prob <- 0.04
n.removed = 1
burn.in = 20
recovery = 5
add00 = c(0.5, 10)
lose01 = 0.1
add10 = 0.05
lose11 = c(0.5, 0.5)
coefAdd = 0.5
coefLose = -0.5
modelGraphs <- runModel(N = N, # Nodes in the network
edge.prob = edge.prob,
n.removed = n.removed,
burn.in = burn.in,
recovery = recovery,
add00 = add00,
lose01 = lose01,
add10 = add10,
lose11 = lose11,
coefAdd = coefAdd,
coefLose = coefLose)$graphs
## Warning: Removed 1 row(s) containing missing values (geom_path).
First, I run the model 100 times and compute the network measures for each of the model runs.
Now, I can make some plots to detect general trends in what happens to the network after removal/rewiring.
# Time slice numbers for line placement
back1 <- which(names(modelGraphs) == "back1")
removed <- which(names(modelGraphs) == "removed")
rewired <- which(names(modelGraphs) == "rewired")
Density behaves the same no matter the number of individuals in the network, just with less variation. To be expected.
## Warning: Removed 100 row(s) containing missing values (geom_path).
## Removed 100 row(s) containing missing values (geom_path).
Mean distance looks like it might have a nonlinear relationship with the number of individuals in the network. Need to investigate this further!
Modularity seems to behave the same no matter the number of individuals in the network.
First, let’s check whether degree and betweenness are indeed highly correlated. We suspect that they are.
Indeed, these are highly correlated. I’m not going to make graphs for betweenness, just degree.
What about the ratio between the first and second changes? Aka: what percentage of the loss/gain is recovered by the rewiring?
## Warning in log(ratio): NaNs produced
## Warning in log(ratio): NaNs produced
## Warning in log(ratio): NaNs produced
## Warning: Removed 159 rows containing non-finite values (stat_smooth).
## Warning: Removed 159 rows containing missing values (geom_point).